Skip to content

fix(extraction): tolerate whitespace in MyBatis close tags and fix qualified include refid#1222

Open
fengshao1227 wants to merge 1 commit into
colbymchenry:mainfrom
fengshao1227:fix/mybatis-whitespace-closetag-refid
Open

fix(extraction): tolerate whitespace in MyBatis close tags and fix qualified include refid#1222
fengshao1227 wants to merge 1 commit into
colbymchenry:mainfrom
fengshao1227:fix/mybatis-whitespace-closetag-refid

Conversation

@fengshao1227

Copy link
Copy Markdown

Summary

Fixes two bugs in the MyBatis/iBatis mapper extractor (src/extraction/mybatis-extractor.ts), both reported and diagnosed in #1209:

  • Whitespace in close tags — a close tag with trailing whitespace (</select >, legal XML) was missed by the statement regex. The non-greedy body overshot to the next real close tag, silently swallowing the statement in between. Fixed by adding \s* before > in the close-tag pattern.
  • Qualified include refid — a fully-qualified <include refid="com.example.M.base"> had every dot replaced with ::, producing com::example::M::base which never matched the fragment node's qualifiedName (com.example.M::base). Fixed by splitting on the last dot only, consistent with qualifyStatement's own logic.

Also fixes the include-offset calculation to derive from the opening tag length rather than subtracting the close tag, so it stays correct when the close tag carries trailing whitespace.

Closes #1209

Test plan

  • Added 4 new test cases in mybatis-extractor-robustness.test.ts:
    • Close tag with trailing space does not swallow the next statement
    • <include> still resolves after a spaced close tag
    • Cross-mapper refid with multi-dot namespace resolves correctly
    • Bare refid regression guard (same-namespace, no dots)
  • All 21 existing + new tests pass (npx vitest run __tests__/mybatis-extractor-robustness.test.ts)

…alified include refid resolution

Two bugs in the MyBatis mapper extractor:

1. A close tag with trailing whitespace (`</select >`, legal XML) was not
   matched by the statement regex, causing the non-greedy body to overshoot
   to the next close tag — silently swallowing the statement in between.
   Fix: add `\s*` before `>` in the close-tag pattern.

2. A fully-qualified `<include refid="com.example.M.base">` had every dot
   replaced with `::`, producing `com::example::M::base` — which never
   matched the fragment node's `qualifiedName` (`com.example.M::base`).
   Fix: split on the last dot only, matching `qualifyStatement`'s logic.

Also fixes the include-offset calculation to derive from the opening tag
length rather than subtracting the close tag, so it stays correct when the
close tag carries trailing whitespace.

Closes colbymchenry#1209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MyBatis extractor: whitespace-close-tag & qualified-refid statement-scan bugs (branches ready)

1 participant